
package com.nuvo.beans;

import com.nuvo.entities.ArticuloCompra;
import com.nuvo.services.ArticuloCompraService;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;


@ManagedBean
@SessionScoped
public class ArticuloCompraController implements Serializable{
    @EJB
    private ArticuloCompraService articuloCompraService;
    
    private ArticuloCompra selected;
    
    private Integer total;
    
    

   
    public ArticuloCompraController() {
    }

    public ArticuloCompra getSelected() {
        if(selected == null){
            selected = new ArticuloCompra();
        
        }
        return selected;
    }
    
    public List<ArticuloCompra> listado(){
        return  articuloCompraService.findAll();
    }
    
    //----metodos del bean---//
    
    
    public String index(){
        return "/articulo_compra/index";
    }
    
    public String nuevo(){
        selected = new ArticuloCompra();
    return "/articulo_compra/new";
    }
    
     
     
     public String guardar() {
         
         total = selected.getCantidad()*selected.getPrecio();
         
         selected.setSubTotal(total);
        articuloCompraService.edit(selected);
        return "/articulo_compra/index";
    }
     
      public String editar(int codigo) {
        selected = articuloCompraService.find(codigo);
        return "/articulo_compra/edit";
    }
      
      public String eliminar(int codigo) {
        selected = articuloCompraService.find(codigo);
        articuloCompraService.remove(selected);
        return "/articulo_compra/index";
    } 
      
      public void clacular(){
      
          
      }
      
}
